home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / umich / utils / bison.arc / MAIN.C < prev    next >
C/C++ Source or Header  |  1988-07-11  |  3KB  |  119 lines

  1. /* Top level entry point of bison,
  2.    Copyright (C) 1984, 1986 Bob Corbett and Free Software Foundation, Inc.
  3.  
  4. BISON is distributed in the hope that it will be useful, but WITHOUT ANY
  5. WARRANTY.  No author or distributor accepts responsibility to anyone
  6. for the consequences of using it or for whether it serves any
  7. particular purpose or works at all, unless he says so in writing.
  8. Refer to the BISON General Public License for full details.
  9.  
  10. Everyone is granted permission to copy, modify and redistribute BISON,
  11. but only under the conditions described in the BISON General Public
  12. License.  A copy of this license is supposed to have been given to you
  13. along with BISON so you can know your rights and responsibilities.  It
  14. should be in a file named COPYING.  Among other things, the copyright
  15. notice and this notice must be preserved on all copies.
  16.  
  17.  In other words, you are welcome to use, share and improve this program.
  18.  You are forbidden to forbid anyone else to use, share and improve
  19.  what you give them.   Help stamp out software-hoarding!  */
  20.  
  21. #include <stdio.h>
  22. #include "machine.h"    /* JF for MAXSHORT */
  23.  
  24. extern    int lineno;
  25. extern    int verboseflag;
  26.  
  27. /* Nonzero means failure has been detected; don't write a parser file.  */
  28. int failure;
  29.  
  30. main(argc, argv)
  31. int argc;
  32. char *argv[];
  33. {
  34.   failure = 0;
  35.   lineno = 0;
  36.   getargs(argc, argv);
  37.   openfiles();
  38.  
  39.   /* read the input.  Copy some parts of it to fguard, faction, ftable and fattrs.
  40.      In file reader.
  41.      The other parts are recorded in the grammar; see gram.h.  */
  42.   reader();
  43.  
  44.   /* record other info about the grammar.  In files derives and nullable.  */
  45.   set_derives();
  46.   set_nullable();
  47.  
  48.   /* convert to nondeterministic finite state machine.  In file LR0.
  49.      See state.h for more info.  */
  50.   generate_states();
  51.  
  52.   /* make it deterministic.  In file lalr.  */
  53.   lalr();
  54.  
  55.   /* Find and record any conflicts: places where one token of lookahead is not
  56.      enough to disambiguate the parsing.  In file conflicts.
  57.      Currently this does not do anything to resolve them;
  58.      the trivial form of conflict resolution that exists is done in output.  */
  59.   initialize_conflicts();
  60.  
  61.   /* print information about results, if requested.  In file print. */
  62.   if (verboseflag)
  63.     verbose();
  64.   else
  65.     terse();
  66.  
  67.   /* output the tables and the parser to ftable.  In file output. */
  68.   output();
  69.   done(failure);
  70. }
  71.  
  72. /* functions to report errors which prevent a parser from being generated */
  73.  
  74. fatal(s)
  75. char *s;
  76. {
  77.   extern char *infile;
  78.  
  79.   if (infile == 0)
  80.     fprintf(stderr, "fatal error: %s\n", s);
  81.   else
  82.     fprintf(stderr, "\"%s\", line %d: %s\n", infile, lineno, s);
  83.   done(1);
  84. }
  85.  
  86.  
  87. /* JF changed to accept/deal with variable args.  Is a real kludge since
  88.    we don't support _doprnt calls */
  89. /*VARARGS1*/
  90. fatals(fmt,x1,x2,x3,x4,x5,x6,x7,x8)
  91. char *fmt;
  92. {
  93.   char buffer[200];
  94.  
  95.   sprintf(buffer, fmt, x1,x2,x3,x4,x5,x6,x7,x8);
  96.   fatal(buffer);
  97. }
  98.  
  99.  
  100.  
  101. toomany(s)
  102. char *s;
  103. {
  104.   char buffer[200];
  105.  
  106.     /* JF new msg */
  107.   sprintf(buffer, "limit of %d exceeded, too many %s", MAXSHORT, s);
  108.   fatal(buffer);
  109. }
  110.  
  111.  
  112.  
  113. berror(s)
  114. char *s;
  115. {
  116.   fprintf(stderr, "internal error, %s\n", s);
  117.   abort();
  118. }
  119.